<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('student/index')}">所有学生</a></li>
        <li><a href="{:url('student/add')}">添加学生</a></li>
    </ul>
    <form class="well form-inline margin-top-20"  method="get" action="{:url('student/index')}">
        学校名称:
        <select name="school_id" id="selectSchool" class="form-control">
            <option value="0">请选择学校</option>
            <volist name="$school" id="vo">
                <if $Request.param.school_id == $vo.id>
                    <option value="{$vo.id}" selected>{$vo.name}</option>
                    <else>
                        <option value="{$vo.id}">{$vo.name}</option>
                    </else>
                </if>
            </volist>
        </select>
        班级名称:
        <select name="room_id" class="form-control" id="room">
            <option value="">请选择班级</option>
            <volist name='room' id="vo">
                <if $Request.param.room_id==$vo.id>
                    <option value="{$vo.id}" selected>{$vo.name}</option>
                    <else/>
                    <option value="{$vo.id}">{$vo.name}</option>
                </if>
            </volist>
        </select>
        学生姓名:
        <input type="text" class="form-control" name="name" style="width: 150px;" value="{$Request.param.name}" placeholder="请输入学生名称">
        <input type="submit" class="btn btn-primary" value="搜索" />
        <a class="btn btn-danger" href="{:url('student/index')}">清空</a>
        <button class="btn btn-danger" type="button" onclick="delAll()">{:lang('DELETE')}</button>
    </form>
    <table class="table table-hover table-bordered table-list">
        <thead>
        <tr>
            <th width="16"><label><input type="checkbox" class="js-check-all" data-direction="x"
                                         data-checklist="js-check-x"></label></th>
            <th width="50">ID</th>
            <th>头像</th>
            <th>学生姓名</th>
            <th>学生性别</th>
            <th>身份证号</th>
            <th>家庭地址</th>
            <th>所属学校</th>
            <th>所属班级</th>
            <th>是否在籍</th>
            <th>创建时间</th>
            <th width="160">{:lang('ACTIONS')}</th>
        </tr>
        </thead>
        <foreach name="student" item="vo">
            <tr>
                <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                           value="{$vo.id}"></td>
                <td>{$vo.id}</td>
                <td>
                    <if $vo.image != ''>
                        <img src="/upload/{$vo.image}" width="50px" height="50px">
                        <else />
                        暂无
                    </if>
                </td>
                <td>{$vo.name}</td>
                <td>
                    <if $vo.sex != '1'>
                        女
                        <else>
                            男
                        </else>
                    </if>
                </td>
                <td>{$vo.idcard}</td>
                <td>{$vo.address}</td>
                <td>{$vo.school_name}</td>
                <td>{$vo.room_name}</td>
                <td>
                    <if $vo.status=='2'>
                        <span style="color:green;">是</span>
                        <else />
                        <span style="color:red;">否</span>
                    </if>
                </td>

                <td>{$vo.create_time}</td>
                <td>
                    <a class="btn btn-xs btn-primary" href="{:url('result/cj',array('id'=>$vo['id']))}">查看成绩</a>
                    <a class="btn btn-xs btn-primary" href="{:url('student/edit',array('id'=>$vo['id']))}">编辑</a>
                    <a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('student/delete',array('id'=>$vo['id']))}">删除</a>
                </td>
            </tr>
        </foreach>
    </table>
    <div class="pagination">{$page}</div>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript" src="__STATIC__/layui/layui.all.js"></script>
<script>
    layui.use('upload',function () {
        var upload=layui.upload;
        var uploadInst=upload.render({
            elem:'#import',
            url:"{:url('student/importExcel')}",
            accept:'file',
            done:function (res) {
                layer.msg('成功导入'+res.success+'条数据');
                setTimeout(function () {
                    location.reload();
                },2000)
            }
        })
    })
</script>
<script>
    $(function () {
        $('#selectSchool').change('click',function () {
            var schoolId=$('#selectSchool').val();
            $.ajax({
                url:"{:url('student/getAdd')}",
                type:"POST",
                data:{school_id:schoolId},
                success:function (res) {
                    $('#room').html(res);
                }
            })
        })
    })
    function delAll() {
        var ids = [];

        //获取选中的id
        $('tbody input').each(function (index,el) {
            if ($(this).prop('checked')){
                ids.push($(this).val())
            }
        });
        layer.confirm('确认要删除吗?',function (index) {
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                url: "{:url('student/delAll')}",
                type: "POST",
                data: {ids:ids},
                success: function (res) {
                    if (res.code == 200){
                        layer.msg(res.msg,{icon:1});
                        setTimeout(function () {
                            location.reload();
                        },1500);
                    } else {
                        layer.msg(res.msg);
                        return false;
                    }
                }
            });
        });
    }
</script>
</body>
</html>